#include <iostream>
#include "Strassen_task.h"
#include <sys/time.h>
#include "TFrame.h"
#include "util.h"


/* User defined constants */
#define my_Numthreads 2 
#define my_Size 1024 

using namespace std;

int main (int argc, char ** argv) {
	// Create a work queue //
	WorkQueue Q;
	Q.setNumThreads(my_Numthreads);
	Q.initThreads();

	// Set up the needed matrices //
	float *a, *b, *c;
	size_t _size = my_Size*my_Size*sizeof(float);	
	a = (float*)malloc(_size);
	b = (float*)malloc(_size);
	c = (float*)malloc(_size);
	printf("%x %f \t %f\n", c, c[0], c[1]);
        
	int i = 0, j = 0;
	for (; i < my_Size ; i++) {
		j = 0;
		for (; j < my_Size ; j++) {
			a[i*my_Size + j] = 2.0;
			b[i*my_Size + j] = 2.0;
			c[i*my_Size + j] = 0.0;
		}
	}

	// Declare a new Strassen Task and put it in the queue and start working //
	TState my_State;
        puts("Before Creating");
	Strassen * my_Strassen = new Strassen(a, b, c, my_Size, &Q, &my_State, 0);
	puts("Strassen Task created");
	timeval tim;
	gettimeofday(&tim, NULL);
	double t1=tim.tv_sec+(tim.tv_usec/1000000.0);	

	Q.addTask(my_Strassen);
	Q.wait_for_threads(); // wait for the threads to come back //
	gettimeofday(&tim, NULL);
	double t2=tim.tv_sec+(tim.tv_usec/1000000.0);	
	printf("%.6lf seconds elapsed\n", t2-t1);

       
	printf("MYRESULS %x %f \t %f\n", c, c[0], c[1]);

	 
        free(a); a = NULL;
        free(b); b = NULL;
        free(c); c = NULL;
	
	return 0;
}
